<!-- 我的收藏 -->
<template>
  <div class="my-store-page">
    <el-row class="search">
      <el-col :span="6">
        <el-input
          placeholder="请输入项目编号"
          prefix-icon="el-icon-search"
          v-model="searchVal"
          size="small"
        />
      </el-col>
      <el-col :span="6">
        <el-button type="primary" size="small" @click="searchChange">搜索</el-button>
      </el-col>
    </el-row>

    <el-row class="table" v-if="listData">
      <el-row class="table-item" v-for="(item,index) in listData" :key="index">
        <el-row type="flex" justify="space-between">
          <el-row type="flex" align="middle">
            <div class="title">{{item.propertyName}}</div>
            <el-tag effect="plain" size="mini">{{propertyType[item.type]}}</el-tag>
            <div class="remain-time">
              距结束：
              <countDown
                :endTime="item.enrollEndTime"
                :propertyNo="item.propertyNo"
                :index="index"
                @timeEnd="timeEnd"
              />
            </div>
          </el-row>
          <div
            class="btn"
            :class="item.state==6?'btn1':'btn2'"
            @click="herfto('propsTrade/tradeinfo',item)"
          >{{propsState[item.state]}}</div>
        </el-row>
        <el-row type="flex" justify="space-between">
          <el-row type="flex">
            <div>项目编号：{{item.propertyNo}}</div>
            <div class="price">挂牌价格：{{item.listingPrice}}</div>
            <div>挂牌截止时间：{{item.enrollEndTime}}</div>
          </el-row>
          <div>项目状态：{{propsState[item.state]}}</div>
        </el-row>
      </el-row>
    </el-row>
    <el-row type="flex" justify="center" style="margin-top:20px">
      <el-pagination
      :hide-on-single-page="true"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="size"
        layout="prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-row>
  </div>
</template>

<script>
import countDown from '../../components/common/CountDown'

import {getPropsList} from '../../api/propsTrade'
import {getPropertyCollectionList} from '@/api/profiles'

import {propsState, propsType} from '@/utils/setting'

export default {
  name: 'MyStore',
  components: {
    countDown
  },
  data() {
    return {
      propsState,
      propertyType: propsType,
      listData: null,
      searchVal: '',
      currentPage: 1,
      total: 0,
      size: 10
    }
  },
  computed: {},
  watch: {},
  methods: {
    herfto(name, item) {
      if (item.state == 6) {
        this.$router.push({
          path: `/${name}`,
          query: {id: item.id}
        })
      }
    },
    timeEnd(propertyNo, index) {
      // 倒计时结束改变项目状态
      // console.log('活动已结束:', propertyNo, index)
      if (this.listData[index].propertyNo == propertyNo) {
        this.listData[index].state = 8
      }
    },
    // 搜索
    searchChange() {
      const _this = this
      _this.listData = null
      _this.getList()
    },
    getList() {
      getPropertyCollectionList(Object.assign({}, {searchSomething: this.searchVal, pageNo: this.currentPage, pageSize: this.size})).then(res => {
        let {
          status,
          data: {
            code,
            message,
            result: {records},
            success
          }
        } = res
        if (status == 200 && code == 200 && success) {
          this.listData = records
        } else {
          this.$message.error(message)
        }
      })
    },
    handleCurrentChange(val) {
      this.listData = []
      this.getList()
    }
  },
  activated() {
    this.getList()
  },
  deactivated() {},
  created() {},
  mounted() {}
}
</script>

<style lang='less' scoped>
.btn2 {
  background: #ccc;
}
.btn1 {
  background: #fbab0b;
}
.table {
  margin-top: 32px;

  &-item {
    padding: 20px 0;
    font-size: 12px;
    color: #656565;
    line-height: 12px;
    border-bottom: 1px solid #ebebeb;
    > .el-row:first-child {
      padding-bottom: 13px;
      .title {
        font-size: 14px;
        color: #333333;
        line-height: 14px;
      }
      .el-tag {
        margin: 0 16px;
      }
      .remain-time {
        font-size: 12px;
        color: #c5151d;
        line-height: 12px;
      }
      .btn {
        width: 90px;
        height: 28px;
        border-radius: 4px;
        text-align: center;
        line-height: 28px;
        font-size: 14px;
        color: #ffffff;
      }
    }
    .price {
      padding: 0 54px;
    }
  }
}
.search {
  .el-button {
    margin-left: 20px;
  }
}
</style>